package cn.tedu.luban.worker.main.repository.impl;

import cn.tedu.luban.worker.main.converter.WorkerCategoryConverter;
import cn.tedu.luban.worker.main.dao.WorkerCategoryDAO;
import cn.tedu.luban.worker.main.repository.WorkerCategoryRepository;
import cn.tedu.luban.worker.protocol.bo.WorkerCategoryBO;
import cn.tedu.luban.worker.protocol.dos.WorkerCategoryDO;
import cn.tedu.luban.worker.protocol.param.WorkerRegistCategoryParam;
import cn.tedu.luban.worker.protocol.param.WorkerRegistParam;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class WorkerCategoryRepositoryImpl implements WorkerCategoryRepository {
    @Autowired(required = false)
    private WorkerCategoryDAO workerCategoryDAO;
    @Autowired
    private WorkerCategoryConverter workerCategoryConverter;
    @Override public void delete(Long userId) {
        workerCategoryDAO.deleteByUserId(userId);
    }

    @Override public void saveWorkerCategories(WorkerRegistParam param) {
        List<WorkerRegistCategoryParam> params = param.getWorkerRegistCategoryParams();
        Long userId = param.getUserId();
        //分类参数中缺少userId
        List<WorkerCategoryDO> workerCategoryDOS = workerCategoryConverter.params2dos(params, userId);
        workerCategoryDAO.batchInsert(workerCategoryDOS);
    }

    @Override public List<WorkerCategoryBO> getFrontCategories(Long userId) {
        List<WorkerCategoryDO> workerCategoryDOS=workerCategoryDAO.selectByUserId(userId);
        return workerCategoryConverter.dos2bos(workerCategoryDOS);
    }

    @Override public List<WorkerCategoryBO> getWorkerCategories(Long userId) {
        List<WorkerCategoryDO> workerCategoryDOS = workerCategoryDAO.selectByUserId(userId);
        return workerCategoryConverter.do2bos(workerCategoryDOS);
    }
}
